package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.DestinationAlltheme;
import cn.wolfcode.luowowo.article.domain.DestinationDay;
import cn.wolfcode.luowowo.article.domain.DestinationMonth;
import cn.wolfcode.luowowo.article.query.DestinationRecommedQuery;
import cn.wolfcode.luowowo.article.service.*;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import cn.wolfcode.luowowo.website.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationFilterController {

    @Reference
    private IDestinationService destinationService;

    @Reference
    private IStrategyThemeService strategyThemeService;

    @Reference
    private IDestinationMonthService destinationMonthService;

    @Reference
    private IDestinationDayService destinationDayService;

    @Reference
    private IDestinationAllthemeService destinationAllthemeService;

    @Reference
    private IDestinationThemeService destinationThemeService;

    @Reference
    private IScenicService scenicService;

    /**
     * 当季主题推荐
     * @return
     * 我们的Ajax异步请求不止可以返回json类型的数据,也可以返回一个页面,局部刷新
     */
    //当季推荐列表
    @RequestMapping("/recommend")
    public String recommend(Model model) {

        //destinationMonth
        List<Destination> list = destinationService.list();

        model.addAttribute("destinationMonth",list);

        //theme1
        List<DestinationAlltheme> bigTheme1 = destinationAllthemeService.listByParent(1L);
        model.addAttribute("bigTheme1",bigTheme1);
        //theme2
        List<DestinationAlltheme> bigTheme2 = destinationAllthemeService.listByParent(2L);
        model.addAttribute("bigTheme2",bigTheme2);
        //theme3
        List<DestinationAlltheme> bigTheme3 = destinationAllthemeService.listByParent(3L);
        model.addAttribute("bigTheme3",bigTheme3);

        return "destination/destination";
    }


    //目的地条件共享
    @RequestMapping("/destFilter")
    public Object destFilter(Model model, Long themeId, @UserParam UserInfo userInfo) {

        //theme1
        List<DestinationAlltheme> bigTheme1 = destinationAllthemeService.listByParent(1L);
        model.addAttribute("bigTheme1",bigTheme1);
        //theme2
        List<DestinationAlltheme> bigTheme2 = destinationAllthemeService.listByParent(2L);
        model.addAttribute("bigTheme2",bigTheme2);
        //theme3
        List<DestinationAlltheme> bigTheme3 = destinationAllthemeService.listByParent(3L);
        model.addAttribute("bigTheme3",bigTheme3);

        //month
        List<DestinationMonth> listMonth = destinationMonthService.list();
        model.addAttribute("listMonth",listMonth);

        //day
        List<DestinationDay> days = destinationDayService.list();
        model.addAttribute("days",days);

        model.addAttribute("themeId",themeId);

        //用户头像
        model.addAttribute("userInfo", userInfo);
        return "destination/destFilter";
    }

    //目的地条件过滤
    @RequestMapping("/monthFilter")
    public Object monthFilter(Model model,@ModelAttribute("qo") DestinationRecommedQuery qo) {

        //dest,景点
        List<Destination> dests = destinationService.listByMonthIdAndThenmeId(qo);

        model.addAttribute("dests",dests);
        return "destination/monthTpl";
    }
}

























